<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>修改定时任务调度</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <script type="text/javascript" src="../../common/js/public.js"></script>
    <script type="text/javascript" src="../../common/js/publicUtils.js"></script>
    <style>
        .layui-input-inline,.buttondiv .layui-input-inline {
            float: left;
            width: 400px !important;
            margin-right: 10px;
        }
        .layui-form-label {
            width: 110px !important;
        }
        .error{
            color: red;
            line-height: 20px;
        }
    </style>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form"  id="quartzform" lay-filter="quartzform">
            <input type="hidden" name="jobId" id="jobId">
            <div class="layui-form-item">
                <label class="layui-form-label" for="jobName"><span style="color: red;">*</span>任务名称</label>
                <div class="layui-input-inline">
                    <input type="text" name="jobName" id="jobName"  placeholder="请输入任务名称" class="layui-input" >
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label" for="jobGroup"><span style="color: red;">*</span>任务组名</label>
                <div class="layui-input-inline">
                    <select id="jobGroup" name="jobGroup">
                        <option value="DEFAULT">默认</option>
                        <option value="SYSTEM">系统</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label" for="invokeTarget"><span style="color: red;">*</span>调用目标字符串</label>
                <div class="layui-input-inline">
                    <input type="text" name="invokeTarget" id="invokeTarget"  placeholder="请输入调用目标字符串" class="layui-input" >
                    <p class="worntype"><i class="layui-icon layui-icon-about"></i>Bean调用示例：ryTask.ryParams('ry')</p>
                    <p class="worntype"><i class="layui-icon layui-icon-about"></i>Class类调用示例：com.ctcemti.quartz.task.RyTask.ryParams('ry')</p>
                    <p class="worntype"><i class="layui-icon layui-icon-about"></i>参数说明：支持字符串，布尔类型，长整型，浮点型，整型</p>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label" for="cronExpression"><span style="color: red;">*</span>cron执行表达式</label>
                <div class="layui-input-inline">
                    <input type="text" name="cronExpression" id="cronExpression"  placeholder="请输入cron执行表达式" class="layui-input" >
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label" for="misfirePolicy"><span style="color: red;">*</span>执行策略</label>
                <div class="layui-input-inline">
                    <select id="misfirePolicy" name="misfirePolicy">
                        <option value="1">立即触发执行</option>
                        <option value="2">触发一次执行</option>
                        <option value="3">放弃触发执行</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><span style="color: red;">*</span>状态</label>
                <div class="layui-input-inline">
                    <input type="radio" name="status" value="0" title="正常" checked>
                    <input type="radio" name="status" value="1" title="停止">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><span style="color: red;">*</span>是否并发执行</label>
                <div class="layui-input-inline">
                    <input type="radio" name="concurrent" value="0" title="允许" checked>
                    <input type="radio" name="concurrent" value="1" title="暂停">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label" for="comment">备注信息</label>
                <div class="layui-input-inline">
                    <textarea name="comment" id="comment" placeholder="请输入备注信息" class="layui-textarea" ></textarea>
                </div>
            </div>
        </form>
    </div>
</div>
<script>
    $(function(){
        layui.use("form",function(){
            var form = layui.form;
        })
    })
    var id = getUrlParam("id");
    init(id);
    function init(id){
        publicAjax (null,"system/quartz/query",
                {
                    "jobId":id
                },true,null,function (r) {
                        if(r.code==2000){
                            layui.use("form",function(){
                                var form = layui.form;
                                form.val("quartzform",{
                                    "jobName":r.data.jobName,
                                    "jobGroup":r.data.jobGroup,
                                    "invokeTarget":r.data.invokeTarget,
                                    "cronExpression":r.data.cronExpression,
                                    "misfirePolicy":r.data.misfirePolicy,
                                    "status":r.data.status,
                                    "comment":r.data.comment,
                                    "concurrent":r.data.concurrent,
                                    "jobId":r.data.jobId,
                                })
                                form.render();
                            })
                        }else{
                            layerror("查询失败",null);
                        }
                });
    }
    /**
     * 保存
     */
    function submit(){
        var data = $("#quartzform").serializeJson();
        var url = 'system/quartz/update';
        var obj = $(validform().form());
        if(!obj[0]){
            return false;
        }
        var result;
        publicAjax (null,url,data,false ,null,function (r) {
            if(r.code==2000){
                laysuccess("更新成功",null);
                result = r;
            }else{
                layerror("更新失败",null);
                result = r;
            }
        });
        return result;
    }


    //编写表单验证函数validform，在验证按钮注册按钮点击事件内调用验证函数对象
    function validform(){
        return $("#quartzform").validate({
            rules : {
                jobName : {
                required:true,
                        normalizer: function( value ) {
                    return $.trim( value );
                }
            },

                jobGroup : {
                required:true,
                        normalizer: function( value ) {
                    return $.trim( value );
                }
            },

                invokeTarget : {
                required:true,
                        normalizer: function( value ) {
                    return $.trim( value );
                }
            },

                cronExpression : {
                required:true,
                        normalizer: function( value ) {
                    return $.trim( value );
                }
            },

                misfirePolicy : {
                required:true,
                        normalizer: function( value ) {
                    return $.trim( value );
                }
            },

                status : {
                required:true,
                        normalizer: function( value ) {
                    return $.trim( value );
                }
            },
                comment : {
                    maxlength: 100,
                        normalizer: function( value ) {
                    return $.trim( value );
                }
            },

                concurrent : {
                required:true,
                        normalizer: function( value ) {
                    return $.trim( value );
                }
            },


    },
        messages : {
            jobName : {
                required:"任务名称不能为空"
             },
            jobGroup : {
                required:"任务组名不能为空"
             },
            invokeTarget : {
                required:"调用目标字符串不能为空"
             },
            cronExpression : {
                required:"cron执行表达式不能为空"
             },
            misfirePolicy : {
                required:"计划执行策略不能为空"
             },
            status : {
                required:"状态不能为空"
             },
            comment : {
                required:"备注信息长度不能超过100"
             },
            concurrent : {
                required:"是否并发执行不能为空"
             },
        }
    });
    }

    function getUrlParam(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return decodeURIComponent(r[2]);
        return null;
    }

</script>
</body>

</html>